﻿using System;
using System.Data;
using System.Data.SqlClient;

namespace Module.QuanTriHeThong.DanhMuc
{
    public class PhanTramHoaHongDichVu : DBInteractionBase
    {
        public string TaiKhoan { get; set; }
        public string ID { get; set; }
        public string MaDichVu { get; set; }
        public string MaChucVu { get; set; }
        public double PhanTramHoaHong { get; set; }

        public bool Insert(PhanTramHoaHongDichVu obj)
        {
            try
            {
                using (var dbcmd = new SqlCommand("PhanTramHoaHongDichVu_Insert", GetConnection()))
                {
                    dbcmd.CommandType = CommandType.StoredProcedure;
                    dbcmd.Parameters.Add(new SqlParameter("@MaDichVu", obj.MaDichVu));
                    dbcmd.Parameters.Add(new SqlParameter("@MaChucVu", obj.MaChucVu));
                    dbcmd.Parameters.Add(new SqlParameter("@PhanTramHoaHong", obj.PhanTramHoaHong));
                    dbcmd.Parameters.Add(new SqlParameter("@TaiKhoan", obj.TaiKhoan));
                    dbcmd.ExecuteNonQuery();
                }
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public bool DeleteByMaDichVu(string madichvu)
        {
            try
            {
                using (var dbcmd = new SqlCommand("PhanTramHoaHongDichVu_DeleteByMaDichVu", GetConnection()))
                {
                    dbcmd.CommandType = CommandType.StoredProcedure;
                    dbcmd.Parameters.Add(new SqlParameter("@MaDichVu", madichvu));
                    dbcmd.ExecuteNonQuery();
                }
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public DataTable PhanTramHoaHongDichVu_SelectByMaDichVu(string madichvu)
        {
            var dt = new DataSet();
            try
            {
                using (var dbcmd = new SqlCommand("PhanTramHoaHongDichVu_SelectByMaDichVu", GetConnection()))
                {
                    dbcmd.CommandType = CommandType.StoredProcedure;
                    dbcmd.Parameters.Add(new SqlParameter("@MaDichVu", madichvu));
                    var dtAdapter = new SqlDataAdapter(dbcmd);
                    dtAdapter.Fill(dt);
                    return dt.Tables[0];
                }
            }
            catch (Exception ex)
            {
                throw new Exception("PhanTramHoaHongDichVu_SelectByMaDichVu: " + ex.Message);
            }
        }
    }
}
